<?php
class AdminController extends BpfController
{
  public function __init()
  {
    $userModel = $this->getModel('user');
    $account = null;
    if (($userid = $userModel->checkLogin())) {
    // 未登录
      if (!($account = $userModel->getUser($userid)) || !$account->status) {
        // 无效用户, 退出登录
        $this->toLoginPage();
      }
    }
    $this->account = $account;
    if (!$this->isLogin() ) {
      $this->toLoginPage();
    }
    $this->getView()->assign('account', $account);
  }

  public function isLogin()
  {
    return isset($this->account);
  }


  public function toLoginPage()
  {
    $router = $this->getRouter();
    if (!in_array($router['action'], $this->allows ?? [])) {
      $this->res->gotoUrl('admin/user/logout');
    }
  }
}
